import {BadRequestException, Body, Controller, Delete, Get, Inject, Post, Query} from "@nestjs/common";
import {ApiBody, ApiOperation, ApiTags} from "@nestjs/swagger";
import {Public} from "~/modules/auth/decorators/public.decorator";
import {StaffTagDelDto, StaffTagSaveDto} from "~/modules/consult/tag/tag.dto";
import {StaffTagService} from "~/modules/consult/tag/tag.service";

@ApiTags("Consult - 咨询师标签")
@Controller('consult/tag')
export class StaffTagController {
  @Inject()
  private readonly staffTagService: StaffTagService

  @Post()
	@Public()
  @ApiOperation({summary: '添加咨询师标签'})
  @ApiBody({type: StaffTagSaveDto})
  async add(@Body() body: StaffTagSaveDto) {
    try {
      return await this.staffTagService.save(body)
    }
    catch (error) {
      throw new BadRequestException(error?.message ?? '添加咨询师标签失败')
    }
  }

  @Delete()
  @ApiOperation({summary: '删除咨询师标签'})
  @ApiBody({type: StaffTagDelDto})
  async del(@Query() query: StaffTagDelDto) {
    try {
      await this.staffTagService.remove(query.id)
      return null
    }
    catch (error) {
      throw new BadRequestException(error?.message ?? '删除咨询师标签失败')
    }
  }

  @Get()
  @ApiOperation({summary: '查询咨询师标签'})
  async find() {
    try {
      return await this.staffTagService.find()
    }
    catch (error) {
      throw new BadRequestException(error?.message ?? '查询咨询师标签失败')
    }
  }
}
